/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package run;

import testutil.TestObjectiveFunction;
import simple.*;
import algorithm.BreedingSelector;
import algorithm.Environment;
import algorithm.ObjectiveFunction;
import algorithm.PopulationBreeder;
import algorithm.PopulationInitializer;
import junit.framework.TestCase;
import testutil.MultiMinimumTestObjectiveFunction;
import testutil.MultiMinimumTestObjectiveFunctionSingleDimension;

/**
 *
 * @author Pierre
 */
public class RunToughGA extends TestCase {

    private int nValues = 3;
    private int bitsPerValue = 16;

    public void testToughGA() {
        final int nGenerations = 100;
        double mutationChance = 0.05;
        double mutationFraction = 0.05;
        int populationSize = 100;

        PopulationInitializer initializer = new BitStringPopulationInitializer(populationSize, bitsPerValue*nValues);
        BreedingSelector selector = new RankRouletteWheelSelector();
        PopulationBreeder crossOverBreeder = new DefaultPopulationBreeder(
                selector,
                new CrossOverOperator());
        PopulationBreeder mutator = new MutationBreeder(mutationChance, mutationFraction);

        ObjectiveFunction obj = new MultiMinimumTestObjectiveFunction();
        Environment environment = new Environment(obj, new DoubleArrayBitStringEncoder(bitsPerValue, nValues));

        SimpleGeneticAlgorithm algo = new SimpleGeneticAlgorithm(
                initializer,
                new NumberOfGenerationsStopCriterion(nGenerations),
                crossOverBreeder,
                mutator,
                environment);
        algo.addGenerationReport(new LogGenerationReport());
        try {
            algo.run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
